﻿<%@ WebHandler Language="C#" Class="GetOverlayCenterPointHandler" %>

using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using Business.Common;
using Business.Map;

public class GetOverlayCenterPointHandler : IHttpHandler
{
    public void ProcessRequest(HttpContext context)
    {
        var mapid = context.Request["mapid"];
        context.Response.ContentType = "text/plain";
        context.Response.Write(GetCenterPointJsonStr(mapid));
    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }

    private string GetCenterPointJsonStr(string mapid)
    {
        var overlayList = new List<MapOverlay>();
        var list = new List<MapPoint>();
        mapid = MapBLL.GetMapidByIID(mapid);
        var dtTempMarkInfo = MapBLL.GetOverlayMarkInfo(mapid);
        var dtTempPoint = MapBLL.GetOverlayPoint(mapid);
        dtTempPoint.Rows.Cast<DataRow>().ToList().ForEach(row => list.Add(new MapPoint
        {
            X = row["x"].ToString(),
            Y = row["y"].ToString(),
        }));
        if (dtTempMarkInfo.Rows.Count > 0)
        {
            overlayList.Add(new MapOverlay
            {
                Markattr = dtTempMarkInfo.Rows[0]["markattr"].ToString(),
                PointList = list
            });
        }
        var result = new MapMarkInfo { OverlayList = overlayList };
        return result.T2Json();
    }
}